package com.miao.elm.controller;

import com.miao.elm.entity.FoodEntity;
import com.miao.elm.service.FoodService;
import com.miao.elm.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


@RestController
@RequestMapping("FoodController")
public class FoodController {
    @Autowired
    private FoodService foodService;

    @RequestMapping("/listFoodByBusinessId")
    public List<FoodEntity> listFoodByBusinessId(@RequestParam("businessId") int businessId){
        return foodService.listFoodByBusinessId(businessId);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{foodId}")
    public R info(@PathVariable("foodId") Integer foodId){
		FoodEntity food = foodService.getById(foodId);

        return R.ok().put("food", food);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody FoodEntity food){
		foodService.save(food);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody FoodEntity food){
		foodService.updateById(food);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] foodIds){
		foodService.removeByIds(Arrays.asList(foodIds));

        return R.ok();
    }

}
